package com.ssm.sfzy.controller;

import com.ssm.sfzy.constant.CommonConstant;
import com.ssm.sfzy.entity.Teacher;
import com.ssm.sfzy.service.TeacherService;
import com.ssm.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @ClassName TeacherController
 * @Author xiaoliu
 * @Date 2024年03月30日 11:27
 */
@RestController
@CrossOrigin
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @GetMapping("/find")
    public Object find(
            @RequestParam(defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            Teacher teacher
    ){
        Map<String, Object> map = teacherService.findPage(pageNum, pageSize, teacher);
        return  Result.success(map);
    }


    @GetMapping("/findById/{id}")
    public Object findById(@PathVariable Integer id){
        Teacher teacher = teacherService.findById(id);
        return Result.success(teacher);
    }


    @PostMapping("/add")
    public Object add(@RequestBody Teacher teacher){
        teacherService.add(teacher);
        return Result.success();
    }

    @PutMapping("/edit")
    public Object edit(@RequestBody Teacher teacher){
        teacherService.edit(teacher);
        return Result.success();
    }
    @DeleteMapping("/remove/{id}")
    public Object remove(@PathVariable Integer id){
        teacherService.remove(id);
        return Result.success();
    }

    @DeleteMapping("/removeBatch/{ids}")
    public Object removeBatch(Integer[] ids){
        teacherService.removeBatch(ids);
        return Result.success();
    }

}
